//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (C) 2007-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.
package com.openbravo.pos.config;

import com.openbravo.pos.base.AppLocal;
import e.odbo.data.bean.IKeyed;

import com.openbravo.data.gui.ComboBoxValEntry;
import com.openbravo.data.user.DirtyManager;
import java.awt.CardLayout;
import java.awt.Component;

import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import com.openbravo.pos.base.AppConfig;

import com.openbravo.pos.base.I_AppConfig;
import com.openbravo.pos.printer.DeviceDisplay;
import com.openbravo.pos.printer.DevicePrinter;
import com.openbravo.pos.printer.config.ParametersPrinter;
import com.openbravo.pos.util.ReportUtils;
import com.openbravo.pos.util.StringParser;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;

import net.xeoh.plugins.base.PluginManager;
import net.xeoh.plugins.base.util.PluginManagerUtil;

//import org.jvnet.substance.SubstanceLookAndFeel;
//import org.jvnet.substance.api.SubstanceSkin;
//import org.jvnet.substance.skin.SkinInfo;

import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JRadioButton;

/**
 *
 * @author adrianromero
 */
public class JPanelConfigGeneral extends javax.swing.JPanel implements PanelConfig {

    private DirtyManager dirty = new DirtyManager();

    private ParametersConfig printer1printerparams;

    private ParametersConfig printer2printerparams;

    private ParametersConfig printer3printerparams;
    
    private ParametersConfig displayparams;
    
    private Map<String,DevicePrinter> printerMap=new HashMap();
    
	private Map<String,DeviceDisplay>  displayMap=new HashMap();

	private String[] printernames;

    /** Creates new form JPanelConfigGeneral */
    public JPanelConfigGeneral() {
    	initComponents();
    }

    private ComboBoxValEntry buildEntry(String prop){
        String localkey="config.general."+prop;
        ComboBoxValEntry entry=new ComboBoxValEntry(prop,AppLocal.getIntString(localkey));
        return entry;
    }

    private ComboBoxValEntry buildIKey(String prop){
        String localkey="config.general."+prop;
        ComboBoxValEntry entry=new ComboBoxValEntry(prop,"");
        return entry;
    }

    public boolean hasChanged() {
        return dirty.isDirty();
    }

    public Component getConfigComponent() {
        return this;
    }

    public void loadProperties(I_AppConfig config) {

        jtxtMachineHostname.setText(config.getProperty("machine.hostname"));

        String lafclass = config.getProperty("swing.defaultlaf");
        jcboLAF.setSelectedItem(null);
        for (int i = 0; i < jcboLAF.getItemCount(); i++) {
            LAFInfo lafinfo = (LAFInfo) jcboLAF.getItemAt(i);
            if (lafinfo.getClassName().equals(lafclass)) {
                jcboLAF.setSelectedIndex(i);
                break;
            }
        }
        // jcboLAF.setSelectedItem(new LookAndFeelInfo());

        jcboMachineScreenmode.setSelectedItem(buildIKey(config.getProperty("machine.screenmode")));
        jcboTicketsBag.setSelectedItem(buildIKey(config.getProperty("machine.ticketsbag")));

        StringParser p = new StringParser(config.getProperty("machine.printer"));
        String sparam = unifySerialInterface(p.nextToken(':'));
        DevicePrinter selectPrinter=printerMap.get(sparam);
        
        if("printer".equals(sparam)){
        	jcboMachinePrinter.setSelectedItem(buildIKey(sparam));
        	m_jPrinterParams1.removeAll();
        	printer1printerparams=new ParametersPrinter(printernames);
        	printer1printerparams.addDirtyManager(dirty);
        	printer1printerparams.setParameters(p);
        	m_jPrinterParams1.add(printer1printerparams.getComponent());
        	m_jPrinterParams1.revalidate();
        	m_jPrinterParams1.repaint();   	
        }else if (selectPrinter!=null) {
        	jcboMachinePrinter.setSelectedItem(buildIKey(sparam));
        	m_jPrinterParams1.removeAll();
        	printer1printerparams=selectPrinter.getConfiguration();
        	printer1printerparams.addDirtyManager(dirty);
        	printer1printerparams.setParameters(p);
        	m_jPrinterParams1.add(printer1printerparams.getComponent());
        	m_jPrinterParams1.revalidate();
        	m_jPrinterParams1.repaint(); 
        } else {
            if("Not defined".equals(sparam))
                sparam="Not_defined";
            jcboMachinePrinter.setSelectedItem(buildIKey(sparam));
            printer1printerparams=null;
            m_jPrinterParams1.removeAll();
        }

        p = new StringParser(config.getProperty("machine.printer.2"));
        sparam = unifySerialInterface(p.nextToken(':'));
        selectPrinter=printerMap.get(sparam);
        
        if("printer".equals(sparam)){
        	jcboMachinePrinter2.setSelectedItem(buildIKey(sparam));
        	m_jPrinterParams2.removeAll();
        	printer2printerparams=new ParametersPrinter(printernames);
        	printer2printerparams.addDirtyManager(dirty);
        	printer2printerparams.setParameters(p);
        	m_jPrinterParams2.add(printer2printerparams.getComponent());
        	m_jPrinterParams2.revalidate();
        	m_jPrinterParams2.repaint();   	
        }else if (selectPrinter!=null) {
        	jcboMachinePrinter2.setSelectedItem(buildIKey(sparam));
        	m_jPrinterParams2.removeAll();
        	printer2printerparams=selectPrinter.getConfiguration();
        	printer2printerparams.addDirtyManager(dirty);
        	printer2printerparams.setParameters(p);
        	m_jPrinterParams2.add(printer2printerparams.getComponent());
        	m_jPrinterParams2.revalidate();
        	m_jPrinterParams2.repaint(); 
        } else {
            if("Not defined".equals(sparam))
                sparam="Not_defined";
            jcboMachinePrinter2.setSelectedItem(buildIKey(sparam));
            printer2printerparams=null;
            m_jPrinterParams2.removeAll();
        }


        p = new StringParser(config.getProperty("machine.printer.3"));
        sparam = unifySerialInterface(p.nextToken(':'));
        selectPrinter=printerMap.get(sparam);
        
        if("printer".equals(sparam)){
        	jcboMachinePrinter3.setSelectedItem(buildIKey(sparam));
        	m_jPrinterParams3.removeAll();
        	printer3printerparams=new ParametersPrinter(printernames);
        	printer3printerparams.addDirtyManager(dirty);
        	printer3printerparams.setParameters(p);
        	m_jPrinterParams3.add(printer3printerparams.getComponent());
        	m_jPrinterParams3.revalidate();
        	m_jPrinterParams3.repaint();   	
        }else if (selectPrinter!=null) {
        	jcboMachinePrinter3.setSelectedItem(buildIKey(sparam));
        	m_jPrinterParams3.removeAll();
        	printer3printerparams=selectPrinter.getConfiguration();
        	printer3printerparams.addDirtyManager(dirty);
        	printer3printerparams.setParameters(p);
        	m_jPrinterParams3.add(printer3printerparams.getComponent());
        	m_jPrinterParams3.revalidate();
        	m_jPrinterParams3.repaint(); 
        } else {
            if("Not defined".equals(sparam))
                sparam="Not_defined";
            jcboMachinePrinter3.setSelectedItem(buildIKey(sparam));
            printer3printerparams=null;
            m_jPrinterParams3.removeAll();
        }

        p = new StringParser(config.getProperty("machine.display"));
        sparam = unifySerialInterface(p.nextToken(':'));
        DeviceDisplay selectDisplay=displayMap.get(sparam);
        
        if (selectDisplay!=null) {
        	jcboMachineDisplay.setSelectedItem(buildIKey(sparam));
        	m_jDisplayParams.removeAll();
        	displayparams=selectDisplay.getConfiguration();
        	displayparams.addDirtyManager(dirty);
        	displayparams.setParameters(p);
        	m_jDisplayParams.add(displayparams.getComponent());
        	m_jDisplayParams.revalidate();
        	m_jDisplayParams.repaint(); 
        } else {
            if("Not defined".equals(sparam))
                sparam="Not_defined";
            jcboMachineDisplay.setSelectedItem(buildIKey(sparam));
            displayparams=null;
            m_jDisplayParams.removeAll();
        }
        
        p = new StringParser(config.getProperty("machine.scale"));
        sparam = p.nextToken(':');
        jcboMachineScale.setSelectedItem(buildIKey(sparam));
        if ("dialog1".equals(sparam) || "samsungesp".equals(sparam)) {
            jcboSerialScale.setSelectedItem(p.nextToken(','));
        }

        p = new StringParser(config.getProperty("machine.scanner"));
        sparam = p.nextToken(':');
        jcboMachineScanner.setSelectedItem(buildIKey(sparam));
        if ("scanpal2".equals(sparam)) {
            jcboSerialScanner.setSelectedItem(p.nextToken(','));
        }
        cboPrinters.setSelectedItem(config.getProperty("machine.printername"));
        
        String printType = config.getProperty(AppConfig.PRINT_TYPE);
        noPrint.setSelected(true);
        if(printType.equalsIgnoreCase(AppConfig.PRINT_TYPE_FLUSH))
            flushPrint.setSelected(true);
        else if(printType.equalsIgnoreCase(AppConfig.PRINT_TYPE_FLUSH))
            realPrint.setSelected(true);
        dirty.setDirty(false);
    }

    public void saveProperties(I_AppConfig config) {

        config.setProperty("machine.hostname", jtxtMachineHostname.getText());

        LAFInfo laf = (LAFInfo) jcboLAF.getSelectedItem();
        config.setProperty("swing.defaultlaf", laf == null
                ? System.getProperty("swing.defaultlaf", "javax.swing.plaf.metal.MetalLookAndFeel")
                : laf.getClassName());

        config.setProperty("machine.screenmode", comboValue(jcboMachineScreenmode.getSelectedItem()));
        config.setProperty("machine.ticketsbag", comboValue(jcboTicketsBag.getSelectedItem()));

        String sMachinePrinter = comboValue(jcboMachinePrinter.getSelectedItem());
        String str=sMachinePrinter;
        if(printer1printerparams!=null){
        	 str=str+ ":" +printer1printerparams.getParameters();
        }
        config.setProperty("machine.printer", str);
        
        String sMachinePrinter2 = comboValue(jcboMachinePrinter2.getSelectedItem());
        str=sMachinePrinter2;
        if(printer2printerparams!=null){
        	 str=str+ ":" +printer2printerparams.getParameters();
        }
        config.setProperty("machine.printer.2", str);
        
        
        String sMachinePrinter3 = comboValue(jcboMachinePrinter3.getSelectedItem());
        str=sMachinePrinter3;
        if(printer3printerparams!=null){
        	 str=str+ ":" +printer3printerparams.getParameters();
        }
        config.setProperty("machine.printer.3", str);
        

        String sMachineDisplay = comboValue(jcboMachineDisplay.getSelectedItem());
        str=sMachineDisplay;
        if(displayparams!=null){
        	 str=str+ ":" +displayparams.getParameters();
        }
        config.setProperty("machine.display", str);

        // La bascula
        String sMachineScale = comboValue(jcboMachineScale.getSelectedItem());
        if ("dialog1".equals(sMachineScale) || "samsungesp".equals(sMachineScale)) {
            config.setProperty("machine.scale", sMachineScale + ":" + comboValue(jcboSerialScale.getSelectedItem()));
        } else {
            config.setProperty("machine.scale", sMachineScale);
        }

        // El scanner
        String sMachineScanner = comboValue(jcboMachineScanner.getSelectedItem());
        if ("scanpal2".equals(sMachineScanner)) {
            config.setProperty("machine.scanner", sMachineScanner + ":" + comboValue(jcboSerialScanner.getSelectedItem()));
        } else {
            config.setProperty("machine.scanner", sMachineScanner);
        }

        config.setProperty("machine.printername", comboValue(cboPrinters.getSelectedItem()));

        if(flushPrint.isSelected())
        	config.setProperty(AppConfig.PRINT_TYPE, AppConfig.PRINT_TYPE_FLUSH);
        else if(realPrint.isSelected())
        	config.setProperty(AppConfig.PRINT_TYPE, AppConfig.PRINT_TYPE_REAl);
        else
        	config.setProperty(AppConfig.PRINT_TYPE, null);    
        dirty.setDirty(false);
    }

    private String unifySerialInterface(String sparam) {

        // for backward compatibility
        return ("rxtx".equals(sparam))
                ? "serial"
                : sparam;
    }

    private String comboValue(Object value) {
        if(value == null)
            return "";
        if(value instanceof IKeyed)
            return ((IKeyed)value).getKey().toString();
        return value.toString();
    }

    private void changeLAF() {

        final LAFInfo laf = (LAFInfo) jcboLAF.getSelectedItem();
        if (laf != null && !laf.getClassName().equals(UIManager.getLookAndFeel().getClass().getName())) {
            // The selected look and feel is different from the current look and feel.
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    try {
                        String lafname = laf.getClassName();
                        Object laf = Class.forName(lafname).newInstance();

                        if (laf instanceof LookAndFeel) {
                            UIManager.setLookAndFeel((LookAndFeel) laf);
                        }// else if (laf instanceof SubstanceSkin) {
                         //   SubstanceLookAndFeel.setSkin((SubstanceSkin) laf);
                        //}

                        SwingUtilities.updateComponentTreeUI(JPanelConfigGeneral.this.getTopLevelAncestor());
                    } catch (Exception e) {
                    }
                }
            });
        }
    }

    private static class LAFInfo {

        private String name;
        private String classname;

        public LAFInfo(String name, String classname) {
            this.name = name;
            this.classname = classname;
        }

        public String getName() {
            return name;
        }

        public String getClassName() {
            return classname;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel13 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jtxtMachineHostname = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jcboLAF = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jcboMachineScreenmode = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        jcboTicketsBag = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        jcboMachineDisplay = new javax.swing.JComboBox();
        m_jDisplayParams = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jlblConnDisplay = new javax.swing.JLabel();
        jcboConnDisplay = new javax.swing.JComboBox();
        jlblDisplayPort = new javax.swing.JLabel();
        jcboSerialDisplay = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        m_jtxtJPOSName = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jcboMachinePrinter = new javax.swing.JComboBox();
        m_jPrinterParams1 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jcboMachinePrinter2 = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        m_jPrinterParams2 = new javax.swing.JPanel();
        jcboMachinePrinter3 = new javax.swing.JComboBox();
        jLabel25 = new javax.swing.JLabel();
        jcboMachineScale = new javax.swing.JComboBox();
        jLabel26 = new javax.swing.JLabel();
        jcboMachineScanner = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        cboPrinters = new javax.swing.JComboBox();
        m_jPrinterParams3 = new javax.swing.JPanel();
        m_jScaleParams = new javax.swing.JPanel();
        jPanel16 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        jlblPrinterPort4 = new javax.swing.JLabel();
        jcboSerialScale = new javax.swing.JComboBox();
        m_jScannerParams = new javax.swing.JPanel();
        jPanel24 = new javax.swing.JPanel();
        jPanel19 = new javax.swing.JPanel();
        jlblPrinterPort5 = new javax.swing.JLabel();
        jcboSerialScanner = new javax.swing.JComboBox();
        buttonGroup1 = new javax.swing.ButtonGroup();

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(AppLocal.getIntString("Label.CashMachine"))); // NOI18N

        jLabel5.setText(AppLocal.getIntString("Label.MachineName")); // NOI18N

        jLabel2.setText(AppLocal.getIntString("label.looknfeel")); // NOI18N

        jLabel6.setText(AppLocal.getIntString("Label.MachineScreen")); // NOI18N

        jLabel16.setText(AppLocal.getIntString("Label.Ticketsbag")); // NOI18N

        jLabel15.setText(AppLocal.getIntString("Label.MachineDisplay")); // NOI18N

        jcboMachineDisplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboMachineDisplayActionPerformed(evt);
            }
        });

        /*m_jDisplayParams.setLayout(new java.awt.CardLayout());
        m_jDisplayParams.add(jPanel2, "empty");

        jlblConnDisplay.setText(AppLocal.getIntString("label.machinedisplayconn")); // NOI18N

        jlblDisplayPort.setText(AppLocal.getIntString("label.machinedisplayport")); // NOI18N

        jcboSerialDisplay.setEditable(true);

        javax.swing.GroupLayout gl_jPanel1 = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(gl_jPanel1);
        gl_jPanel1.setHorizontalGroup(
            gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel1.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblConnDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboConnDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlblDisplayPort, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboSerialDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(56, Short.MAX_VALUE))
        );
        gl_jPanel1.setVerticalGroup(
            gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel1.createSequentialGroup()
                .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcboConnDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblDisplayPort)
                    .addComponent(jcboSerialDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblConnDisplay))
                .addGap(59, 59, 59))
        );

        m_jDisplayParams.add(jPanel1, "comm");

        jLabel20.setText(AppLocal.getIntString("Label.Name")); // NOI18N

        javax.swing.GroupLayout gl_jPanel3 = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(gl_jPanel3);
        gl_jPanel3.setHorizontalGroup(
            gl_jPanel3.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel3.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(m_jtxtJPOSName, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(270, Short.MAX_VALUE))
        );
        gl_jPanel3.setVerticalGroup(
            gl_jPanel3.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel3.createSequentialGroup()
                .addGroup(gl_jPanel3.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(m_jtxtJPOSName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addGap(184, 184, 184))
        );

        m_jDisplayParams.add(jPanel3, "javapos");
       */
        
        jLabel7.setText(AppLocal.getIntString("Label.MachinePrinter")); // NOI18N

        jcboMachinePrinter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboMachinePrinterActionPerformed(evt);
            }
        });

        jLabel18.setText(AppLocal.getIntString("Label.MachinePrinter2")); // NOI18N

        jcboMachinePrinter2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboMachinePrinter2ActionPerformed(evt);
            }
        });

        jLabel19.setText(AppLocal.getIntString("Label.MachinePrinter3"));

        jcboMachinePrinter3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboMachinePrinter3ActionPerformed(evt);
            }
        });

        jLabel25.setText(AppLocal.getIntString("label.scale")); // NOI18N

        jcboMachineScale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboMachineScaleActionPerformed(evt);
            }
        });

        jLabel26.setText(AppLocal.getIntString("label.scanner")); // NOI18N

        jcboMachineScanner.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboMachineScannerActionPerformed(evt);
            }
        });

        jLabel1.setText(AppLocal.getIntString("label.reportsprinter"));

        m_jScaleParams.setLayout(new java.awt.CardLayout());
        m_jScaleParams.add(jPanel16, "empty");

        jlblPrinterPort4.setText(AppLocal.getIntString("label.machineprinterport")); // NOI18N

        jcboSerialScale.setEditable(true);

        javax.swing.GroupLayout gl_jPanel17 = new javax.swing.GroupLayout(jPanel17);
        jPanel17.setLayout(gl_jPanel17);
        gl_jPanel17.setHorizontalGroup(
            gl_jPanel17.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel17.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblPrinterPort4, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboSerialScale, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(270, Short.MAX_VALUE))
        );
        gl_jPanel17.setVerticalGroup(
            gl_jPanel17.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel17.createSequentialGroup()
                .addGroup(gl_jPanel17.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcboSerialScale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblPrinterPort4))
                .addGap(135, 135, 135))
        );

        m_jScaleParams.add(jPanel17, "comm");

        m_jScannerParams.setLayout(new java.awt.CardLayout());
        m_jScannerParams.add(jPanel24, "empty");

        jlblPrinterPort5.setText(AppLocal.getIntString("label.machineprinterport")); // NOI18N

        jcboSerialScanner.setEditable(true);

        javax.swing.GroupLayout gl_jPanel19 = new javax.swing.GroupLayout(jPanel19);
        jPanel19.setLayout(gl_jPanel19);
        gl_jPanel19.setHorizontalGroup(
            gl_jPanel19.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel19.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblPrinterPort5, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboSerialScanner, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(270, Short.MAX_VALUE))
        );
        gl_jPanel19.setVerticalGroup(
            gl_jPanel19.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel19.createSequentialGroup()
                .addGroup(gl_jPanel19.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcboSerialScanner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblPrinterPort5))
                .addGap(235, 235, 235))
        );

        m_jScannerParams.add(jPanel19, "comm");
        
        JPanel panel = new JPanel();

        javax.swing.GroupLayout gl_jPanel13 = new javax.swing.GroupLayout(jPanel13);
        gl_jPanel13.setHorizontalGroup(
        	gl_jPanel13.createParallelGroup(Alignment.LEADING)
        		.addGroup(gl_jPanel13.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addComponent(jLabel15, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(jcboMachineDisplay, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(m_jDisplayParams, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addComponent(jLabel7, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(jcboMachinePrinter, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(m_jPrinterParams1, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addComponent(jLabel18, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(jcboMachinePrinter2, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(m_jPrinterParams2, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addComponent(jLabel19, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(jcboMachinePrinter3, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(m_jPrinterParams3, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addComponent(jLabel25, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(jcboMachineScale, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(m_jScaleParams, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        						.addGroup(gl_jPanel13.createSequentialGroup()
        							.addComponent(jLabel26, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        							.addPreferredGap(ComponentPlacement.RELATED)
        							.addComponent(jcboMachineScanner, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE))
        						.addGroup(gl_jPanel13.createSequentialGroup()
        							.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        							.addPreferredGap(ComponentPlacement.RELATED)
        							.addComponent(cboPrinters, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)))
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(m_jScannerParams, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        						.addGroup(gl_jPanel13.createSequentialGroup()
        							.addComponent(jLabel5, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        							.addPreferredGap(ComponentPlacement.RELATED)
        							.addComponent(jtxtMachineHostname, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE))
        						.addGroup(gl_jPanel13.createSequentialGroup()
        							.addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        							.addPreferredGap(ComponentPlacement.RELATED)
        							.addComponent(jcboLAF, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE))
        						.addGroup(gl_jPanel13.createSequentialGroup()
        							.addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        							.addPreferredGap(ComponentPlacement.RELATED)
        							.addComponent(jcboMachineScreenmode, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE))
        						.addGroup(gl_jPanel13.createSequentialGroup()
        							.addComponent(jLabel16, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
        							.addPreferredGap(ComponentPlacement.RELATED)
        							.addComponent(jcboTicketsBag, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)))
        					.addGap(58)
        					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 189, GroupLayout.PREFERRED_SIZE)))
        			.addContainerGap())
        );
        gl_jPanel13.setVerticalGroup(
        	gl_jPanel13.createParallelGroup(Alignment.LEADING)
        		.addGroup(gl_jPanel13.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel5)
        						.addComponent(jtxtMachineHostname, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        					.addGap(6)
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel2)
        						.addComponent(jcboLAF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel6)
        						.addComponent(jcboMachineScreenmode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel16)
        						.addComponent(jcboTicketsBag, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
        				.addComponent(panel, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE))
        			.addGap(18)
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        					.addComponent(jLabel15)
        					.addComponent(jcboMachineDisplay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        				.addComponent(m_jDisplayParams, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        					.addComponent(jLabel7)
        					.addComponent(jcboMachinePrinter, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        				.addComponent(m_jPrinterParams1, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        					.addComponent(jLabel18)
        					.addComponent(jcboMachinePrinter2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        				.addComponent(m_jPrinterParams2, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        					.addComponent(jLabel19)
        					.addComponent(jcboMachinePrinter3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        				.addComponent(m_jPrinterParams3, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        					.addComponent(jLabel25)
        					.addComponent(jcboMachineScale, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        				.addComponent(m_jScaleParams, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(gl_jPanel13.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_jPanel13.createSequentialGroup()
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel26)
        						.addComponent(jcboMachineScanner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        					.addPreferredGap(ComponentPlacement.UNRELATED)
        					.addGroup(gl_jPanel13.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel1)
        						.addComponent(cboPrinters, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
        				.addComponent(m_jScannerParams, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE))
        			.addContainerGap())
        );
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        
        noPrint = new JRadioButton(AppLocal.getIntString("list.noPrint"));
        buttonGroup1.add(noPrint);
        panel.add(noPrint);
        
        flushPrint = new JRadioButton(AppLocal.getIntString("list.flushPrint"));
        buttonGroup1.add(flushPrint);
        panel.add(flushPrint);
        
        realPrint = new JRadioButton(AppLocal.getIntString("list.realPrint"));
        buttonGroup1.add(realPrint);
        panel.add(realPrint);
        jPanel13.setLayout(gl_jPanel13);
        m_jPrinterParams3.setLayout(new BorderLayout(0, 0));
        m_jPrinterParams2.setLayout(new BoxLayout(m_jPrinterParams2, BoxLayout.X_AXIS));
        m_jPrinterParams1.setLayout(new BorderLayout(0, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        layout.setHorizontalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap()
        			.addComponent(jPanel13, GroupLayout.PREFERRED_SIZE, 667, GroupLayout.PREFERRED_SIZE)
        			.addContainerGap(106, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap()
        			.addComponent(jPanel13, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        			.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        this.setLayout(layout);
    }// </editor-fold>//GEN-END:initComponents

    private void jcboMachineScannerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboMachineScannerActionPerformed
        CardLayout cl = (CardLayout) (m_jScannerParams.getLayout());
        String selectedItem = comboValue(jcboMachineScanner.getSelectedItem());
        if ("scanpal2".equals(selectedItem)) {
            cl.show(m_jScannerParams, "comm");
        } else {
            cl.show(m_jScannerParams, "empty");
        }
    }//GEN-LAST:event_jcboMachineScannerActionPerformed

    private void jcboMachineScaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboMachineScaleActionPerformed
        CardLayout cl = (CardLayout) (m_jScaleParams.getLayout());
         String selectedItem = comboValue(jcboMachineScale.getSelectedItem());
        if ("dialog1".equals(selectedItem) || "samsungesp".equals(selectedItem)) {
            cl.show(m_jScaleParams, "comm");
        } else {
            cl.show(m_jScaleParams, "empty");
        }
    }//GEN-LAST:event_jcboMachineScaleActionPerformed

    private void jcboMachinePrinter3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboMachinePrinter3ActionPerformed
         String selectedItem = comboValue(jcboMachinePrinter3.getSelectedItem());
         DevicePrinter selectPrinter=printerMap.get(selectedItem);
         if("printer".equals(selectedItem)){	
         	m_jPrinterParams3.removeAll();
         	printer3printerparams=new ParametersPrinter(printernames);
         	printer3printerparams.addDirtyManager(dirty);
         	m_jPrinterParams3.add(printer3printerparams.getComponent());
         	m_jPrinterParams3.revalidate();
         	m_jPrinterParams3.repaint();   	
         }else if (selectPrinter!=null) {
         	m_jPrinterParams3.removeAll();
         	printer3printerparams=selectPrinter.getConfiguration();
         	printer3printerparams.addDirtyManager(dirty);
         	m_jPrinterParams3.add(printer3printerparams.getComponent());
         	m_jPrinterParams3.revalidate();
         	m_jPrinterParams3.repaint(); 
         } else {
             printer3printerparams=null;
             m_jPrinterParams3.removeAll();
             m_jPrinterParams3.revalidate();
         	m_jPrinterParams3.repaint(); 
         }
    }//GEN-LAST:event_jcboMachinePrinter3ActionPerformed

    private void jcboMachinePrinter2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboMachinePrinter2ActionPerformed
    	String selectedItem = comboValue(jcboMachinePrinter2.getSelectedItem());
        DevicePrinter selectPrinter=printerMap.get(selectedItem);
        if("printer".equals(selectedItem)){	
        	m_jPrinterParams2.removeAll();
        	printer2printerparams=new ParametersPrinter(printernames);
        	printer2printerparams.addDirtyManager(dirty);
        	m_jPrinterParams2.add(printer2printerparams.getComponent());
        	m_jPrinterParams2.revalidate();
        	m_jPrinterParams2.repaint();   	
        }else if (selectPrinter!=null) {
        	m_jPrinterParams2.removeAll();
        	printer2printerparams=selectPrinter.getConfiguration();
        	printer2printerparams.addDirtyManager(dirty);
        	m_jPrinterParams2.add(printer2printerparams.getComponent());
        	m_jPrinterParams2.revalidate();
        	m_jPrinterParams2.repaint(); 
        } else {
            printer2printerparams=null;
            m_jPrinterParams2.removeAll();
            m_jPrinterParams2.revalidate();
        	m_jPrinterParams2.repaint(); 
        }
    }//GEN-LAST:event_jcboMachinePrinter2ActionPerformed

    private void jcboMachineDisplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboMachineDisplayActionPerformed
       
    	String selectedItem = comboValue(jcboMachineDisplay.getSelectedItem());
        DeviceDisplay selectDisplay=displayMap.get(selectedItem);
        if (selectDisplay!=null)  {
        	m_jDisplayParams.removeAll();
        	displayparams=selectDisplay.getConfiguration();
        	displayparams.addDirtyManager(dirty);
        	m_jDisplayParams.add(displayparams.getComponent());
        	m_jDisplayParams.revalidate();
        	m_jDisplayParams.repaint(); 
        } else {
        	displayparams=null;
        	m_jDisplayParams.removeAll();
        	m_jDisplayParams.revalidate();
        	m_jDisplayParams.repaint(); 
        }
    }//GEN-LAST:event_jcboMachineDisplayActionPerformed

    private void jcboMachinePrinterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboMachinePrinterActionPerformed

        String selectedItem = comboValue(jcboMachinePrinter.getSelectedItem());
        DevicePrinter selectPrinter=printerMap.get(selectedItem);
        if("printer".equals(selectedItem)){	
        	m_jPrinterParams1.removeAll();
        	printer1printerparams=new ParametersPrinter(printernames);
        	printer1printerparams.addDirtyManager(dirty);
        	m_jPrinterParams1.add(printer1printerparams.getComponent());
        	m_jPrinterParams1.revalidate();
        	m_jPrinterParams1.repaint();   	
        }else if (selectPrinter!=null) {
        	m_jPrinterParams1.removeAll();
        	printer1printerparams=selectPrinter.getConfiguration();
        	printer1printerparams.addDirtyManager(dirty);
        	m_jPrinterParams1.add(printer1printerparams.getComponent());
        	m_jPrinterParams1.revalidate();
        	m_jPrinterParams1.repaint(); 
        } else {
            printer1printerparams=null;
            m_jPrinterParams1.removeAll();
            m_jPrinterParams1.revalidate();
        	m_jPrinterParams1.repaint(); 
        }
    }//GEN-LAST:event_jcboMachinePrinterActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cboPrinters;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel24;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JComboBox jcboConnDisplay;
    private javax.swing.JComboBox jcboLAF;
    private javax.swing.JComboBox jcboMachineDisplay;
    private javax.swing.JComboBox jcboMachinePrinter;
    private javax.swing.JComboBox jcboMachinePrinter2;
    private javax.swing.JComboBox jcboMachinePrinter3;
    private javax.swing.JComboBox jcboMachineScale;
    private javax.swing.JComboBox jcboMachineScanner;
    private javax.swing.JComboBox jcboMachineScreenmode;
    private javax.swing.JComboBox jcboSerialDisplay;
    private javax.swing.JComboBox jcboSerialScale;
    private javax.swing.JComboBox jcboSerialScanner;
    private javax.swing.JComboBox jcboTicketsBag;
    private javax.swing.JLabel jlblConnDisplay;
    private javax.swing.JLabel jlblDisplayPort;
    private javax.swing.JLabel jlblPrinterPort4;
    private javax.swing.JLabel jlblPrinterPort5;
    private javax.swing.JTextField jtxtMachineHostname;
    private javax.swing.JPanel m_jDisplayParams;
    private javax.swing.JPanel m_jPrinterParams1;
    private javax.swing.JPanel m_jPrinterParams2;
    private javax.swing.JPanel m_jPrinterParams3;
    private javax.swing.JPanel m_jScaleParams;
    private javax.swing.JPanel m_jScannerParams;
    private javax.swing.JTextField m_jtxtJPOSName;


    // End of variables declaration//GEN-END:variables

	@Override
	public void init(PluginManager pmf) {
		
        printernames = ReportUtils.getPrintNames();

        jtxtMachineHostname.getDocument().addDocumentListener(dirty);
        jcboLAF.addActionListener(dirty);
        jcboMachineScreenmode.addActionListener(dirty);
        jcboTicketsBag.addActionListener(dirty);

        jcboMachineDisplay.addActionListener(dirty);
        jcboConnDisplay.addActionListener(dirty);
        jcboSerialDisplay.addActionListener(dirty);
        m_jtxtJPOSName.getDocument().addDocumentListener(dirty);
        /*
         * Obtain multiple plugins
         */
        PluginManagerUtil pmu = new PluginManagerUtil(pmf);
        
        
        jcboMachinePrinter.addActionListener(dirty);
        
        jcboMachinePrinter2.addActionListener(dirty);

        jcboMachinePrinter3.addActionListener(dirty);


        jcboMachineScale.addActionListener(dirty);
        jcboSerialScale.addActionListener(dirty);

        jcboMachineScanner.addActionListener(dirty);
        jcboSerialScanner.addActionListener(dirty);

        cboPrinters.addActionListener(dirty);

        noPrint.addActionListener(dirty);
        flushPrint.addActionListener(dirty);
        realPrint.addActionListener(dirty);
        
//        // Openbravo Skin
//        jcboLAF.addItem(new UIManager.LookAndFeelInfo("Openbravo", "com.openbravo.pos.skin.OpenbravoLookAndFeel"));

        // Installed skins
        LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
        for (int i = 0; i < lafs.length; i++) {
            jcboLAF.addItem(new LAFInfo(lafs[i].getName(), lafs[i].getClassName()));
        }

        // Substance skins
        // new SubstanceLookAndFeel(); // TODO: Remove in Substance 5.0. Workaround for Substance 4.3 to initialize static variables
        //Map<String, SkinInfo> skins = SubstanceLookAndFeel.getAllSkins();
        //for (SkinInfo skin : skins.values()) {
        //    jcboLAF.addItem(new LAFInfo(skin.getDisplayName(), skin.getClassName()));
        //}

        jcboLAF.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeLAF();
            }
        });

        jcboMachineScreenmode.addItem(buildEntry("window"));
        jcboMachineScreenmode.addItem(buildEntry("fullscreen"));

        jcboTicketsBag.addItem(buildEntry("simple"));
        jcboTicketsBag.addItem(buildEntry("standard"));
        jcboTicketsBag.addItem(buildEntry("restaurant"));
        //jcboTicketsBag.addItem(buildEntry("grogshop"));
        
        
        final Collection<DevicePrinter> printers = pmu.getPlugins(DevicePrinter.class);
        
        // Printer 1
        jcboMachinePrinter.addItem(buildEntry("screen"));
        jcboMachinePrinter.addItem(buildEntry("printer"));
        jcboMachinePrinter.addItem(buildEntry("Not_defined"));
        for(DevicePrinter printer:printers){
        	printerMap.put(printer.getPrinterType(), printer);
        	jcboMachinePrinter.addItem(buildEntry(printer.getPrinterType()));
        }
        
        // Printer 2
        jcboMachinePrinter2.addItem(buildEntry("screen"));
        jcboMachinePrinter2.addItem(buildEntry("printer"));
        jcboMachinePrinter2.addItem(buildEntry("Not_defined"));
        for(DevicePrinter printer:printers){
        	jcboMachinePrinter2.addItem(buildEntry(printer.getPrinterType()));
        }
               
        // Printer 3
        jcboMachinePrinter3.addItem(buildEntry("screen"));
        jcboMachinePrinter3.addItem(buildEntry("printer"));
        jcboMachinePrinter3.addItem(buildEntry("Not_defined"));
        for(DevicePrinter printer:printers){
        	jcboMachinePrinter3.addItem(buildEntry(printer.getPrinterType()));
        }
        

        // Display
        jcboMachineDisplay.addItem(buildEntry("screen"));
        jcboMachineDisplay.addItem(buildEntry("window"));
        jcboMachineDisplay.addItem(buildEntry("Not_defined"));

        final Collection<DeviceDisplay> displays = pmu.getPlugins(DeviceDisplay.class);

        for(DeviceDisplay display:displays){
        	displayMap.put(display.getDisplayType(), display);
        	jcboMachineDisplay.addItem(buildEntry(display.getDisplayType()));
        }

        // Scale
        jcboMachineScale.addItem(buildEntry("screen"));
        jcboMachineScale.addItem(buildEntry("dialog1"));
        jcboMachineScale.addItem(buildEntry("samsungesp"));
        jcboMachineScale.addItem(buildEntry("Not_defined"));

        jcboSerialScale.addItem("COM1");
        jcboSerialScale.addItem("COM2");
        jcboSerialScale.addItem("COM3");
        jcboSerialScale.addItem("COM4");
        jcboSerialScale.addItem("/dev/ttyS0");
        jcboSerialScale.addItem("/dev/ttyS1");
        jcboSerialScale.addItem("/dev/ttyS2");
        jcboSerialScale.addItem("/dev/ttyS3");

        // Scanner
        jcboMachineScanner.addItem(buildEntry("scanpal2"));
        jcboMachineScanner.addItem(buildEntry("Not_defined"));

        jcboSerialScanner.addItem("COM1");
        jcboSerialScanner.addItem("COM2");
        jcboSerialScanner.addItem("COM3");
        jcboSerialScanner.addItem("COM4");
        jcboSerialScanner.addItem("/dev/ttyS0");
        jcboSerialScanner.addItem("/dev/ttyS1");
        jcboSerialScanner.addItem("/dev/ttyS2");
        jcboSerialScanner.addItem("/dev/ttyS3");

        // Printers
        cboPrinters.addItem("(Default)");
        cboPrinters.addItem("(Show dialog)");
        for (String name : printernames) {
            cboPrinters.addItem(name);
        }
	}
	
	private javax.swing.ButtonGroup buttonGroup1;
	private JRadioButton noPrint;
	private JRadioButton flushPrint;
	private JRadioButton realPrint;
}
